package com.ouyang.controller;


import com.ouyang.Service.UpdatePwdService;
import com.ouyang.poji.User;
import com.sun.istack.internal.NotNull;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpSession;

@Controller
public class UpdatePwdController {

    @Autowired
    private UpdatePwdService updatePwdService;

    @RequestMapping("/updatepwd")
    public String update ( Model model, String rnewpassword, HttpSession session ) {
        User user = (User) session.getAttribute("user");
        if (user != null) {
            String username = user.getUserName();
            int flag = updatePwdService.update(username, rnewpassword);
            if (flag == 1) {
                model.addAttribute("message", "密码修改成功");
            } else {
                model.addAttribute("message", "密码修改失败");
            }
            return "pwdmodify";
        } else {
            model.addAttribute("message", "密码修改失败");
            return "pwdmodify";
        }
    }
}
